home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / text / tex / amiweb2c.lha / AmiWeb2c-2.1 / texmf / pastex / rexx / TeXEdit.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1997-02-09  |  10.8 KB  |  429 lines

  1. /*
  2. ** AREXX $VER:TeXedit.rexx V1.45 (12.11.1995)
  3. **
  4. ** This ARexx script is called from virtex (or initex) in case of an
  5. ** error or if the 'e' command is used, and it's given the current file
  6. ** and line number as arguments. It may be called from the TeX-server too.
  7. ** We will successively call CygnusEd (CED) or Micro(GNU)Emacs (MG) to
  8. ** load the file and the logfile. Other editors welcome!
  9. **
  10. ** INPUTS:
  11. **    1: filename to edit (please no spaces in filename)
  12. **    2: line where error occured
  13. **
  14. ** BUGS:
  15. **    GETCLIP("TEXFILE") gets precedence over any other information for
  16. **    retrieving the logfile, so if you alternately start virtex directly
  17. **    from CLI while the server is active, the wrong files may be loaded.
  18. **
  19. **    This file tries to cope with the following version (PasTeX 1.2a)
  20. **    > This is a PD-Version of Pas-TeX (made Jan 30 1991 [br]/[hes])
  21. **    > This is TeX, C Version 3.1
  22. **    (The logfile is sometimes put at the wrong place.)
  23. **
  24. **    Does not handle names relative to the local root correctly (like ":foo/bar")
  25. **
  26. **    See each editor relative bugs below.
  27. **
  28. ** FILES:
  29. **    Rexx:NameStruc
  30. **    LIBS:rexxsupport.library
  31. **
  32. ** AUTHORS:
  33. **    J\"org H\"ohle, since March 91
  34. **    Georg Hessmann, previous version
  35. **
  36. ** CHANGES:
  37. **    Modifications for personal use by Andreas Scherer, 1993, 1994.
  38. **    12.11.95: Search for `l.NUMBER' in the first column only in order
  39. **              to use this script with LaTeX output.
  40. */
  41.  
  42. If ~Show('Libraries','rexxsupport.library') Then
  43.   If ~AddLib('rexxsupport.library',0,-30,0) Then Do
  44.     Say "Konnte 'rexxsupport.library' nicht öffnen!"
  45.     Exit 20
  46.   End
  47.  
  48. /*
  49. ** The TeX server may want to know that we have been called.
  50. */
  51. Call SetClip("TEXTIME",TIME('s'))
  52.  
  53. Parse Arg FILENAME NUMBER .
  54.  
  55. /*
  56. ** If the TeX 'e' command was used to call the editor,
  57. ** don't ask if files should be loaded.
  58. */
  59. If "EDIT" ~= Upper(MyGetEnv("TEXREXX")) Then
  60.   ASKLOAD = 0
  61. Else
  62.   ASKLOAD = 1
  63.  
  64. Parse Value NameStruc(FILENAME) With IVOL IDIRS IBASE .
  65.  
  66. /*
  67. ** The idea in the following statements is to get an absolute path
  68. ** for <filename>. The result will be stored in <errnfile>. For example,
  69. ** "CD TeX:bar" "virtex foo" should give <filename>=foo, and
  70. ** <errnfile>=TeX:bar/foo. This is necessary because the editor doesn't
  71. ** know where file foo is located, but will be able to load file
  72. ** TeX:bar/foo.
  73. */
  74.  
  75. MAINNAME = GetClip("TEXFILE")
  76. If "" = MAINNAME Then Do
  77. /*
  78. ** TeX has not been started through some Start_TeX.#? script.
  79. ** We have a hard time finding the right directories.
  80. */
  81.  
  82.   TEXDIR = Pragma('d')
  83.  
  84. /*
  85. ** Amiga OS dirnames should end with either `:' or `/'.
  86. ** Thus you need just append the filename.
  87. */
  88.   If Right(TEXDIR,1) ~= ':' & Right(TEXDIR,1) ~= '/' Then
  89.     TEXDIR = TEXDIR'/'
  90.  
  91.   If 0 = IVOL Then Do
  92.     ERRNFILE = TEXDIR||SubStr(FILENAME,1+IVOL)
  93. /*
  94. ** The logfile is in the current dir.
  95. */
  96.     LOGFILE = TEXDIR||SubStr(FILENAME,1+IVOL+IDIRS,IBASE)".log"
  97.   End; Else Do
  98.     ERRNFILE = FILENAME
  99.     If 0 = IDIRS Then
  100. /*
  101. ** This is a bug in virtex from PasTeX12a (made Jan 30 1991 [br]/[hes])
  102. ** The logfile is *not* in virtex's directory, but rather in the
  103. ** source's directory if a device name, but no subsequent directory was
  104. ** given. I.e, virtex (CD in RAM) TeX:sample would put the errorfile in
  105. ** TeX: and not in RAM: as it should be.
  106. */
  107.       LOGFILE = Left(FILENAME,IVOL+IDIRS+IBASE)".log"
  108.     Else
  109.       LOGFILE = TEXDIR||SubStr(FILENAME,1+IVOL+IDIRS,IBASE)".log"
  110.     End
  111.   Drop TEXDIR
  112. End; Else Do
  113. /*
  114. ** TeX was started through Start_TeX.#? scripts.
  115. ** "TEXFILE" tells us CD and the main file.
  116. */
  117.   Parse Value NameStruc(MAINNAME) With MVOL MDIRS MBASE .
  118.  
  119.   If 0 ~= IVOL Then
  120.     ERRNFILE = FILENAME
  121.   Else
  122.     ERRNFILE = Left(MAINNAME,MVOL+MDIRS)||SubStr(FILENAME,1+IVOL)
  123.  
  124.   LOGFILE = Left(MAINNAME,MVOL+MDIRS+MBASE)".log"
  125.   Drop MVOL MDIRS MBASE
  126. End
  127.  
  128. /*
  129. ** 0 = ibase would mean that the call was incorrect, for example when
  130. ** TEXREXXEDIT says "TeXedit.rexx" and not "TeXedit.rexx %s %d"
  131. */
  132. If 0 = IBASE | ~Exists(ERRNFILE) Then Do
  133.   Say "TeXedit.rexx: Konnte fehlerhafte Datei nicht finden."
  134.   Exit 10
  135. End; Else If ~Exists(LOGFILE) Then Do
  136.   Say "TeXedit.rexx: Konnte Logfile nicht finden."
  137.   LOGFILE = ""
  138. /*
  139. ** But we continue.
  140. */
  141. End
  142.  
  143. Drop IVOL IDIRS IBASE
  144.  
  145. /*
  146. ** Here starts each editor's specific part.
  147. */
  148.  
  149. /*
  150. ** Cygnus Ed Professional Version 3.5+
  151. */
  152. If Show('Port','rexx_ced') Then Do
  153.   Address 'rexx_ced'
  154.  
  155.   Options Results
  156.  
  157.   CEDtoFront
  158.  
  159. /*
  160. ** The following should not be commented out, as this macro is called
  161. ** asynchronously, and it would be very bad for the user to have it's
  162. ** input mixed with the newly loaded files. Popping up a requester
  163. ** ensures that the user does not type in something and waits for the
  164. ** files to be loaded. This is the method I use for synchronization. (JCH)
  165. */
  166.   If ASKLOAD Then Do
  167.     Okay2 "TeX fand einen Fehler in der Datei"'0A'X"'"ERRNFILE"'. Datei laden?"
  168.     If 1 ~= RESULT Then
  169.       Exit 0
  170.   End
  171.  
  172. /*
  173. ** Make sure the TEX-file is loaded.  This works with CED 3.5+ only.
  174. ** There was no mechanism to make sure that the errorneous file was
  175. ** actually loaded in one of the views.  If it wasn't, the next command
  176. ** would open a second view for the log file and a *third* for the
  177. ** TeX-file, but half of the CED screen was left empty with `Unnamed.'
  178. ** You could replace this by `jump to file' for CED 2.12.
  179. */
  180.   OW ERRNFILE
  181.  
  182. /*
  183. ** TODO: We should really delete old logfiles automatically, without letting
  184. **       CED open a requester to ask if an old modified file may be
  185. **       overwritten or not.
  186. */
  187.  
  188.   If "" ~= LOGFILE Then Do
  189.     'jump to file "'LOGFILE'"'
  190.  
  191. /*
  192. ** Always assume the logfile currently loaded is old,
  193. ** because TeX generated a new one.
  194. */
  195.     If 0 ~= RESULT Then
  196.       Quit
  197.  
  198.     Open new
  199.     Open '"'LOGFILE'"'
  200.  
  201. /*
  202. ** Now it's non-editable.
  203. */
  204.     Editable file
  205.     Beg of file
  206.  
  207. /*
  208. ** If we don't have the line number: search the number in the logfile. (hes)
  209. */
  210.     If 0 ~= NUMBER Then
  211.       'Search for' "l."NUMBER
  212.     Else Do
  213. /*
  214. ** LaTeX mit seinen wilden Meldungen im Logfile müllt alles zu.  Es ist
  215. ** gar nicht unwahrscheinlich, daß `l.' auftaucht, ohne eine Zeilennummer
  216. ** zu markieren.  Da ich davon ausgehe, daß bei Aufruf dieses Scripts ein
  217. ** Fehler vorliegt, suche ich solange nach `l.', bis es in der ersten
  218. ** Spalte steht.  Die weitere Verarbeitung bleibt unverändert.
  219. ** 12.11.1995 (as)
  220. */
  221.       Do Until 1 = COLUMN
  222.         'Search for' "l."
  223.         FOUND = RESULT
  224.         If FOUND Then Do
  225.           Right
  226.           Status CursorColumn
  227.           COLUMN = RESULT
  228.         End
  229.         Else COLUMN = 1
  230.       End
  231.  
  232. /*
  233. ** Take the current line from CED.
  234. */
  235.       'Status 55'
  236.       Parse Var RESULT "l." NUMBER .
  237.  
  238. /*
  239. ** Save the current line plus 1 of the log file
  240. */
  241.       'Status 57'
  242.       DUMMY = SetClip("CURRENTLOGLINE",RESULT+2)
  243.     End
  244.  
  245.   End; Else
  246.     Okay1 "Konnte kein richtiges Logfile finden!"
  247.  
  248. /*
  249. ** The following line should really read "jump to file errnfile" and not
  250. ** filename, because I have done extra work to get the right directory. But
  251. ** this information is only in errnfile, which contains an absolute pathname,
  252. ** and not in filename, which is the parameter supplied by virtex or initex,
  253. ** usually a relative pathname. CED's current directory is not necessarily
  254. ** virtex's one. It also seems that CED is not smart enough as to make the
  255. ** difference between foo:tgmoae/myfile and bar:tgmoab/myfile. If I say
  256. ** jump to file foo:tgmoae/myfile it may as well jump to bar:tgmoab/myfile,
  257. ** whichever window comes first.
  258. */
  259.   'jump to file "'ERRNFILE'"'
  260.   If 0 = RESULT Then Do
  261. /*
  262. ** Not reached with `OW ERRNFILE' above.
  263. */
  264.     Open new
  265.     Open '"'errnfile'"'
  266.   End
  267.  
  268. /*
  269. ** TODO: another editor may have modified the disk file, or the user
  270. ** the currently loaded file, while virtex compiled an old version. How
  271. ** can I get rid of that stupid filerequester in that case? I said "open
  272. ** errnfile", so why does CED pop up a filerequester (and may put the
  273. ** user in the wrong directory too)?
  274. */
  275.  
  276.   If 0 ~= NUMBER Then
  277.     JumpTo NUMBER
  278.  
  279.   Beg of line
  280.  
  281.   Exit 0
  282. End
  283. /*
  284. ** End of CED part.
  285. */
  286.  
  287. /*
  288. ** Micro(Gnu)Emacs (MG), to be found on AmigaLibDisk352.
  289. */
  290. If Show('Port','mg') Then Do
  291.   Address 'mg'
  292.  
  293.   Options Results
  294.  
  295. /*
  296. ** The following waits until MG is deiconified.
  297. */
  298.   'amiga-window-to-top'
  299.  
  300. /*
  301. ** We need to prevent the user from continuing to type and thus
  302. ** modifying the newly created buffers. I choose the rexx-lock/unlock
  303. ** method to synchronise with the user because MG3b4 has some cursor
  304. ** position/display bugs: the cursor may erroneously appear in some
  305. ** buffer and overwrite it (on the screen only), and not appear in the
  306. ** bottom line where it belongs.
  307. */
  308.  
  309.   If ASKLOAD Then Do
  310. /*
  311. ** This is dangerous if this script aborts.
  312. */
  313.     'rexx-lock'
  314.  
  315.     Address Value RESULT
  316.  
  317.     'rexx-request "TeX fand einen Fehler. Datei laden? "'
  318.     RETC = RC
  319.     RETS = RESULT
  320.  
  321.     'rexx-unlock'
  322.  
  323.     Address Value RESULT
  324.  
  325.     If 1 < RETC | Left(Upper(RETS),1) = 'N' Then Do
  326.       'rexx-display ""'
  327.       Exit 0
  328.     End
  329.  
  330.     Drop RETC RETS
  331.   End
  332.  
  333.   'find-file "'ERRNFILE'"'
  334. /*
  335. ** MG doesn't seem to set the RC value on a find-file.
  336. */
  337.   'rexx-buffer' BUF
  338.  
  339. /*
  340. ** buf.1 is the buffer name, buf.3 the number of lines.
  341. */
  342.   If NUMBER < BUF.3 Then Do
  343.     'delete-other-windows'
  344.  
  345.     If "" ~= LOGFILE Then Do
  346.       'split-window-vertically'
  347.  
  348. /*
  349. ** Now get rid of old logfiles. Here I make sure that I get rid of
  350. ** every suspicious logfile, because multiple pathes may lead to the same
  351. ** file, as for example SYS:TeX/sample.log & TeX:sample.log.
  352. */
  353.       'rexx-buffer-list' BUFFERS
  354.  
  355.       Parse Value NameStruc(LOGFILE) With IVOL IDIRS IBASE
  356.  
  357.       LOGNAME = Upper(SubStr(LOGFILE,1+IVOL+IDIRS))
  358.  
  359.       Do I=1 To BUFFERS.0
  360.         If 0 < Index(Upper(BUFFERS.I.FILE),LOGNAME) Then Do
  361.           'switch-to-buffer "'BUFFERS.I.NAME'"'
  362.           'not-modified'
  363.           'kill-buffer "'BUFFERS.I.NAME'"'
  364.         End
  365.       End
  366.  
  367.       'find-file "'LOGFILE'"'
  368. /*
  369. ** MG doesn't seem to set the RC value.
  370. */
  371.       'beginning-of-buffer'
  372.  
  373.       If 0 ~= NUMBER Then
  374.         're-search-forward "^l."NUMBER'
  375.       Else Do
  376. /*
  377. ** Try to use normal search?
  378. */
  379.         're-search-forward "^l."' /* ^ means begin of line */
  380.  
  381. /*
  382. ** If search successfull get current line contents.
  383. */
  384.         If 0 = RC Then Do
  385.           'rexx-line'
  386.           Parse Var RESULT "l."NUMBER .
  387.         End
  388.       End
  389.  
  390.       'other-window'
  391.       'rexx-display "Now what''s that error?"'
  392.     End; Else
  393.       'rexx-display "Konnte kein richtiges Logfile finden!"'
  394.  
  395.     If 0 ~= NUMBER Then
  396.       'goto-line 'NUMBER
  397.   End; Else Do
  398.     'not-modified'
  399.     'kill-buffer "'BUF.NAME'"'
  400.     'rexx-display "Konnte fehlerhafte Datei nicht finden!"'
  401.     Exit 5
  402.   End
  403.  
  404.   Exit 0
  405. End
  406. /*
  407. ** End of MG part.
  408. */
  409.  
  410. /*
  411. ** Write macros for your favorite editor here.
  412. */
  413.  
  414. Say "TeXedit.rexx: Kein unterstützter Editor aktiv."
  415. Exit 10
  416.  
  417. /*
  418. ** When will ARexx supply GetEnv/SetEnv?
  419. */
  420. MyGetEnv: Procedure
  421. Parse Arg NAME
  422.  
  423. If Open(TEMPFILE,"ENV:"NAME,'r') Then Do
  424.   GIVES = Readln(TEMPFILE)
  425.   Call Close TEMPFILE
  426. End; Else GIVES = ""
  427.  
  428. Return GIVES
  429.